import { get, post } from "@/utils/network";
import { getChanganToken } from "@/utils/base/token-util";
// import mock from "./mock.json";
// import mockTravel from "./mock-travel.json";
import { YEAR } from "@/config/constants";
import commonBaseURL from "@/config/request/base-url";
import CryptoJS from "crypto-js";
import qs from "qs";
const baseURL = commonBaseURL.yearUrl;
const SIGN = "qeodimlfomhsfklpcthmygvpfyfqvheq";
export const getYearReportStats = () => {
  //  return mock;
  //  /operationReport/aacghinn/yearReport;
  return get("/ichangan/yearReport", {
    params: {
      year: YEAR,
    },
    headers: {
      identityToken: getChanganToken(),
    },
    baseURL,
  });
};
export const getCaHomeToken = (loginId: string) => {
  const timestamp = new Date().getTime();
  console.log(
    "md5",
    timestamp,
    qs.stringify({
      appId: "ichangan",
      timestamp,
    }) + "qeodimlfomhsfklpcthmygvpfyfqvheq"
  );
  return post(
    "/neixuan/api/ichangan/getAccessToken",
    {
      loginId,
    },
    {
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        appId: "ichangan",
        sign: CryptoJS.MD5(
          qs.stringify({
            appId: "ichangan",
            timestamp,
          }) + SIGN
        )
          .toString()
          .toUpperCase(),
        timestamp,
      },

      baseURL: commonBaseURL.caHomeUrl,
    }
  );
};
export const getCaHomeData = async (loginId: string) => {
  const res = await getCaHomeToken(loginId);
  console.log("长安之家token", loginId, "---", res);
  const token = res.result.token;
  const timestamp = new Date().getTime();
  const sign = CryptoJS.MD5(
    qs.stringify({
      appId: "ichangan",
      timestamp,
      token,
    }) + SIGN
  )
    .toString()
    .toUpperCase();
  return get(
    "/neixuan/api/ichangan/statistics?" +
      qs.stringify({
        token,
      }),
    {
      headers: {
        "Content-Type": "application/json;charset=utf-8",
        appId: "ichangan",
        sign,
        timestamp,
      },
      baseURL: commonBaseURL.caHomeUrl,
    }
  );
};
export const postSaveKeyWord = (keyWord: string) => {
  // /operationReport/aacghinn/saveKeyWord
  return post("/saveKeyWord", null, {
    params: {
      year: YEAR,
      keyWord,
      token: getChanganToken(),
    },
    baseURL,
  });
};
export const getSelfWish = () => {
  return get("/wish/self", {
    headers: {
      identityToken: getChanganToken(),
    },
    baseURL,
  });
};
export const setSelfWish = (wishContent: string) => {
  return post(
    "/wish",
    {
      wishContent,
    },
    {
      headers: {
        identityToken: getChanganToken(),
      },
      baseURL,
    }
  );
};
export const getOtherPersonWish = (size: number) => {
  return get(
    "/wish?" +
      qs.stringify({
        size,
      }),
    {
      headers: {
        identityToken: getChanganToken(),
      },
      baseURL,
    }
  );
};
